Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutex to tree move function, fix #1518 #2082

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

svenseeberg
Copy link
Member

@svenseeberg svenseeberg commented Feb 18, 2023

Short description

Prevent race conditions in page tree. This is no replacement for database transactions. This would not catch problems where the process dies in the middle of changing a tree structure.

Proposed changes

  • Use django-db-mutex module to implement a per class mutex that allows only one page tree move operation at a time.
  • This can be replaced with basically the same functionality within tree beard if it works.
  • As we have multiple processes in production, the database back end is used for communication. We could also use Redis, which would actually be a little faster. However, the app implements it this way and it should be good enough for testing if we continue to have 500 errors in our logs.
  • Saving of other data should continue even when the move action fails. The user receives a notification about the failure to move the page.

Side effects

  • In a few cases users may have to wait a little longer.
  • If getting the mutex fails, the user as to redo the action.
  • The mutex timeout / TTL seems to have no effect that I could verify. However this should still be better than the status quo. In a test I added a sleep for 60s in the block that requires the mutex and set the mutex TTL to 5s. No error was raised.

Resolved issues

Fixes: #1518


Pull Request Review Guidelines

@svenseeberg svenseeberg requested a review from a team as a code owner February 18, 2023 14:21
@codeclimate
Copy link

codeclimate bot commented Feb 18, 2023

Code Climate has analyzed commit e43e493 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 56.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 75.2% (0.0% change).

View more on Code Climate.

@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch from d53eaf3 to 99237f5 Compare February 18, 2023 14:25
@svenseeberg svenseeberg marked this pull request as draft February 18, 2023 14:27
@svenseeberg
Copy link
Member Author

I will improve the user notification and error handling a little before we merge this.

@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch 7 times, most recently from e9a80c0 to 2f1696d Compare February 18, 2023 17:32
@svenseeberg svenseeberg marked this pull request as ready for review February 18, 2023 17:40
Copy link
Member

@timobrembeck timobrembeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this will hopefully reduce our problems! 🤞

integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
Pipfile Outdated Show resolved Hide resolved
@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch from 2f1696d to b527a79 Compare February 18, 2023 20:34
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch 2 times, most recently from de8846f to 058dce1 Compare February 19, 2023 13:23
@svenseeberg
Copy link
Member Author

Using pylint 2.16.2 for python 3.9.15
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.Exception' ?) instead.
************* Module integreat_cms.cms.models.abstract_tree_node
integreat_cms/cms/models/abstract_tree_node.py:297:20: E1101: Instance of 'AbstractTreeNode' has no 'best_translation' member (no-member)
integreat_cms/cms/models/abstract_tree_node.py:304:20: E1101: Instance of 'AbstractTreeNode' has no 'best_translation' member (no-member)

... a few more things need fixing.

integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
integreat_cms/cms/models/abstract_tree_node.py Outdated Show resolved Hide resolved
Pipfile.lock Outdated Show resolved Hide resolved
@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch 2 times, most recently from b359a71 to 97fe210 Compare February 19, 2023 18:28
@svenseeberg svenseeberg changed the title Add mutex to page tree move function, fix #1518 Add mutex to tree move function, fix #1518 Feb 19, 2023
@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch from 97fe210 to 18c4292 Compare February 21, 2023 13:19
Copy link
Member

@timobrembeck timobrembeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

* Use django-db-mutex module to implement a mutex that allows only
  one page tree move operation at a time.

Co-authored-by: Timo Ludwig <[email protected]>
@svenseeberg svenseeberg force-pushed the bugfix/tree-beard-mutex branch from 18c4292 to e43e493 Compare February 21, 2023 13:25
@svenseeberg
Copy link
Member Author

@timoludwig @ulliholtgrave lets merge and deploy? I can have a close look at the prod CMS the remaining day.

Copy link
Member

@ulliholtgrave ulliholtgrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

@timobrembeck
Copy link
Member

timobrembeck commented Feb 21, 2023

One caveat I just noticed: The pages are also moved when the page form is submitted, so in theory we also need to put the page form into the same mutex? 🤔
But this PR can be merged anyways, it's definitely an improvement even if it doesn't fix #1518 completely!

@svenseeberg
Copy link
Member Author

Yes lets merge and continue that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race conditions in tree operations causing Internal Server Errors
3 participants